package com.ymm.lulutong.repo;

import com.ymm.system.api.dto.PutOnCargoRequest;
import com.ymm.system.api.dto.ShipperCargoBriefResponse;
import com.ymm.system.api.dto.ShipperCargoDetailResponse;
import com.ymm.system.api.facade.SystemShipperCargoService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Service
public class SystemShipperCargoServiceRepo {
    @Reference(version = "server")
//    @Reference
    SystemShipperCargoService systemShipperCargoService;

    public com.ymm.lulutong.utils.Result<Long> cargoDeliver(PutOnCargoRequest putOnCargoRequest, Long shipperId) {
        return systemResult2ShipperResult(systemShipperCargoService.cargoDeliver(putOnCargoRequest, shipperId));
    }

    public com.ymm.lulutong.utils.Result<Long> cancelCargo(Long cargoId, Long shipperId) throws Exception {
        return systemResult2ShipperResult(systemShipperCargoService.cancelCargo(cargoId, shipperId));
    }

    public com.ymm.lulutong.utils.Result<List<ShipperCargoBriefResponse>> getOnshelfCargos(Long shipperId) {
        return systemResult2ShipperResult(systemShipperCargoService.getOnshelfCargos(shipperId));
    }

    public com.ymm.lulutong.utils.Result<List<ShipperCargoBriefResponse>> getOffshelfCargos(Long shipperId) {
        return systemResult2ShipperResult(systemShipperCargoService.getOffshelfCargos(shipperId));
    }

    public com.ymm.lulutong.utils.Result<ShipperCargoDetailResponse> getCargoInfoByCargoId(Long cargoId) {
        return systemResult2ShipperResult(systemShipperCargoService.getCargoInfoByCargoId(cargoId));
    }

    public com.ymm.lulutong.utils.Result<String> uploadCargoPhoto(Long shipperId, MultipartFile image){
        return systemResult2ShipperResult(systemShipperCargoService.uploadCargoPhoto(shipperId, image));
    }

    public com.ymm.lulutong.utils.Result<Long> payForCargoSuccess(Long shipperId, Long cargoId) {
        return systemResult2ShipperResult(systemShipperCargoService.payForCargoSuccess(shipperId, cargoId));
    }

    private com.ymm.lulutong.utils.Result systemResult2ShipperResult(com.ymm.system.api.utils.Result result) {
        if (result.isSuccess()) {
            return com.ymm.lulutong.utils.Result.success(result.getData());
        }
        return com.ymm.lulutong.utils.Result.fail(result.getData(), result.getCode(), result.getMessage());
    }
}
